#ifndef KCPAGENT_H
#define KCPAGENT_H
#include <string>
#include "kcp.h"
#include "kcpserver.h"


using namespace std;
class KCPServer;

//Agent 和 Erlang上层业务逻辑对象联系起来 解析报文来获知是握手联系对象 还是其它
//Agent 不用每个报文都区分可以给上层实现一个绑定AgentID即可绑定前和绑定后 绑定前Id = 0 绑定后Id != 0
//Bind接口
//有UDP port就可以足够上层业务逻辑绑定了
class KCPAgent
{
public:
	KCPAgent(string ipPort, KCPServer *s){
		remoteEnd = ipPort;
		kcpServer = s;
		kcp = shared_ptr<KCP>(new KCP());
		kcp->kcpAgent = this;
		//kcp->outputFunc = [this](shared_ptr<KCPPacket> pa){this->SendPacket(pa);};
		//kcp->closeEventHandler = [this]{this->KCPClosed();};
	}

	void ReceiveData(shared_ptr<std::vector<unsigned char> > data);
	void Update(double delta);
	void SendPacket(shared_ptr<KCPPacket> pa);
	//底层KCP向上关闭
	void KCPClosed();

	void SendData(shared_ptr<std::vector<unsigned char> > data);
	string remoteEnd;

	//业务层关闭
	void Close();
private:
	KCPServer *kcpServer;
	shared_ptr<KCP> kcp;
	
	bool IsClose = false;
};

#endif
